package com.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * 描述:
 *
 * @author luzhongfu
 * Created by lucky on 2020-05-09 4:27 PM
 */
public class FutureTest {

    public void runFutureTask(){
        FutureTask<Integer> integerFutureTask = new FutureTask<Integer>(new call());
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.submit(integerFutureTask);
        executorService.shutdown();

    }


    public static void main(String[] args) {
        FutureTest test = new FutureTest();
        test.runFutureTask();
    }

    static class call implements Callable<Integer> {

        private int k =100;

        private int run(){
            for (int i = 0 ; i < 1000000 ; i ++){
                k = i;
            }
            System.out.println(k);
            return k;
        }


        @Override
        public Integer call() throws Exception {
            return run();
        }
    }
}
